import type { FieldConfig } from '@/components/TableFilter.vue'
import { getFormFields } from '@/utils/formUtils'
import type { FormFieldConfig } from '@/types/form'
import { cloneDeep } from 'lodash'

// 表格列配置
export const tableColumns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '推廣標題',
    dataIndex: 'title',
  },
  {
    title: '類型',
    dataIndex: 'type',
  },
  {
    title: '優先順序',
    dataIndex: 'priority',
  },
  {
    title: '生效日期',
    dataIndex: 'validFrom',
  },
  {
    title: '截止日期',
    dataIndex: 'validTo',
  },
  {
    title: '狀態',
    dataIndex: 'status',
  },
  {
    title: '修改人',
    dataIndex: 'updatedBy',
  },
  {
    title: '修改時間',
    dataIndex: 'updatedAt',
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
  },
]
// 過濾項配置
export const filterFields: FieldConfig[] = [
  {
    name: 'title',
    label: '推廣標題',
    type: 'input',
    placeholder: '請輸入推廣標題',
  },
  {
    name: 'type',
    label: '類型',
    type: 'select',
    placeholder: '請選擇優惠類型',
    options: [
      { value: 0, label: '全部' },
      { value: 1, label: 'AIA醫療計劃' },
      { value: 2, label: '定額優惠券' },
      { value: 3, label: '折扣卡' },
    ],
  },
]

// 表單字段配置
const FormField: Record<string, FormFieldConfig> = {
  title: {
    label: '推廣標題',
    type: 'input',
    placeholder: '請輸入推廣標題',
    rules: [{ required: true, message: '請輸入推廣標題' }],
  },
  type: {
    label: '類型',
    type: 'radio',
    placeholder: '請選擇優惠類型',
    rules: [{ required: true, message: '請選擇優惠類型' }],
    options: [
      { key: 1, label: 'AIA醫療計劃' },
      { key: 2, label: '定額優惠券' },
      { key: 3, label: '折扣卡' },
    ],
  },
  validDate: {
    label: '有效日期',
    type: 'daterange',
    rules: [{ required: true, message: '請選擇有效日期' }],
  },
  priority: {
    label: '優先順序',
    type: 'number',
    placeholder: '請輸入優先順序',
    tooltip: '優先順序，數字越大優先級越高',
  },
  status: {
    label: '狀態',
    type: 'radio',
    placeholder: '請選擇狀態',
    rules: [{ required: true, message: '請選擇狀態' }],
    options: [
      { key: 1, label: '啟用' },
      { key: 0, label: '禁用' },
    ],
  },

  remark: {
    label: '備註',
    type: 'input',
    placeholder: '請輸入備註',
  },
}

// 創建表單字段
export const getCreateFieldConfig = (fields?: string[]) => {
   let createFormFields = cloneDeep(FormField)
  // createFormFields.type.disabled = false
  return getFormFields(createFormFields, fields)
}

export const getEditFieldConfig = (fields?: string[]) => {
  // 修改類型不能修改
  let editFormFields =cloneDeep(FormField)
  editFormFields.type.disabled = true
  return getFormFields(editFormFields, fields)
}
